# -*- coding: utf-8 -*-
# Please refer to `https://api.fanyi.baidu.com/doc/21` for complete api document
import re

import requests

exec(open('../utils.py', 'r').read())
from my_token import token

url = f'https://aip.baidubce.com/rpc/2.0/mt/texttrans/v1?access_token={token}'

q = 'hello'  # example: hello
# For list of language codes, please refer to `https://ai.baidu.com/ai-doc/MT/4kqryjku9#语种列表`
from_lang = 'en'  # example: en
to_lang = 'zh'  # example: zh
term_ids = ''  # 术语库id，多个逗号隔开

# Build request
headers = {'Content-Type': 'application/json'}

if __name__ == '__main__':
    text = input_multilines('please input text:')
    q = format_doxygen_comment(text)
    payload = {'q': q, 'from': from_lang, 'to': to_lang, 'termIds': term_ids}
    # Send request
    r = requests.post(url, params=payload, headers=headers)
    result = r.json()
    
    # Show response
    # print(json.dumps(result, indent=4, ensure_ascii=False))
    
    for paragraph in r.json()['result']['trans_result']:
        print(paragraph['src'])
    
    print()
    
    for paragraph in r.json()['result']['trans_result']:
        print(paragraph['dst'])
